package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;

import com.cskaoyan.bean.MarketKeyword;
import com.cskaoyan.bean.param.BaseParam;

import com.cskaoyan.bean.param.CommonData;
import com.cskaoyan.bean.wubang.bo.KeywordBO;
import com.cskaoyan.service.KeywordService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author wubang
 * @description TODO
 * @date 2022/6/27 20:10
 */

@RestController
@RequestMapping("admin/keyword")
public class KeywordController {

    @Autowired
    KeywordService keywordService;

    @RequiresPermissions(value = {"*","admin:keyword:list"},logical = Logical.OR)
    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam, String keyword,String url) {
        CommonData<MarketKeyword> keywords = keywordService.selectKeywordList(baseParam,keyword,url);
        return BaseRespVo.ok(keywords);
    }

    @RequiresPermissions(value = {"*","admin:keyword:create"},logical = Logical.OR)
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody KeywordBO keywordBO) {
        MarketKeyword keyword=keywordService.createKeyword(keywordBO);
        return BaseRespVo.ok(keyword);
    }

    @RequiresPermissions(value = {"*","admin:keyword:delete"},logical = Logical.OR)
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketKeyword marketKeyword) {
        keywordService.deleteKeyword(marketKeyword);
        return BaseRespVo.ok();
    }
    @RequiresPermissions(value = {"*","admin:keyword:update"},logical = Logical.OR)
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketKeyword marketKeyword) {
        MarketKeyword keyword=keywordService.updateKeyword(marketKeyword);
        return BaseRespVo.ok(keyword);
    }
}
